# -*-coding:utf-8-*-
"""
@project: python-project
@Time: 2024-07-15 13:17
@Author: Loneliness_Burial
@File: numpy求累乘和求累和.py
@Motto: 深情不改必坠死海
@software: pycharm
@version: python 3.7
"""

import numpy as np

# 累和
arr = np.array([3, 1, 2])
print("创建的一维数组为:\n", arr)
arr_res = arr.cumsum()
print("该数组累和为：\n", arr_res)
arr = np.random.randint(1, 8, (3, 4))
print("创建的二维数组为:\n", arr)
arr_res = arr.cumsum(axis=0)
print("该数组按纵轴累和为：\n", arr_res)
# 累加乘
arr = np.random.randint(1, 5, (2, 3))
print("创建的二维数组为:\n", arr)
arr_res = arr.cumprod()
print("该数组累加乘为：\n", arr_res)
arr_res = arr.cumprod(axis=1)
print("该数组按横轴累加乘为:\n", arr_res)
